import React, { Component } from 'react';
import './App.css';

class App extends Component {
  constructor() {
    super()
    this.state = { users: [] };
  }
  fetchUsers() {
    return fetch('/user/list', { accpet: "application/json" })
      .then(res => {
        return res.json()
          .then(json => {
            this.setState({ users: json.data })
          })
      })
  }

  registerUser() {
    return fetch('/user/register', { accpet: "application/json" ,method:"Post"});
  }

  getArticle() {
    return fetch('/article/get', { accpet: "application/json" });
  }
  render() {
    return (
      <div className="App">
        <p className="App-intro" onClick={this.fetchUsers.bind(this)}>
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
        <button onClick={this.registerUser.bind(this)}>register</button>
        <button onClick={this.getArticle.bind(this)}>查询</button>
        {this.state.users.map((user, index) => {
          return (<h1 key={index}>{user.name}</h1>)
        })}
      </div>
    );
  }
}

export default App;
